package com.weiyu.bultrasound.core.service.Impl;

import com.weiyu.bultrasound.core.dao.FilesMapper;
import com.weiyu.bultrasound.core.model.entity.Files;
import com.weiyu.bultrasound.core.service.FilesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 *@description 
 *@author abner chow
 *@date 2019-08-13 15:11
 */
@Service
public class FilesServiceImpl implements FilesService {

    @Autowired
    FilesMapper filesMapper;

    @Override
    public Files getById(Long id) {
        return filesMapper.getById(id);
    }

    /**
     * @description 更新记录
     * @Param: [record]
     * @Return: java.lang.Boolean
     * @Author: abner chow
     * @Date: 2019/8/13 15:15
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean updateById(Files record) {
        Boolean flag = Boolean.FALSE;
        int i = filesMapper.updateById(record);
        if (i > 0) {
            flag = Boolean.TRUE;
        }
        return flag;
    }


    /**
     * @description 批量更新
     * @Param: [list]
     * @Return: java.lang.Boolean
     * @Author: abner chow
     * @Date: 2019/8/13 15:15
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean insertByBatch(List list) {
        Boolean flag = Boolean.FALSE;
        int i = filesMapper.insertByBatch(list);
        if (i > 0) {
            flag = Boolean.TRUE;
        }
        return flag;
    }

    /**
     * @description 根据请求单获取文件列表
     * @Param: [applicationsId]
     * @Return: java.util.List<com.weiyu.bultrasound.core.model.entity.Files>
     * @Author: abner chow
     * @Date: 2019/8/16 11:34
     */
    @Override
    public List<Files> getByApplicationsId(Long applicationsId) {
        return filesMapper.getList(Files.builder().applicationsId(applicationsId).build());
    }


    /**
     * @description 根据applicationsId获取未同步到ftp的文件列表
     * @Param: [applicationsId]
     * @Return: java.util.List<com.weiyu.bultrasound.core.model.entity.Files>
     * @Author: abner chow
     * @Date: 2019/8/20 17:42
     */
    @Override
    public List<Files> getUnSynchronizeList(Long applicationsId) {
        return filesMapper.getUnSynchronizeList(applicationsId);
    }


    /**
     * @description 根据applicationsId获取已同步到ftp的文件列表
     * @Param: [applicationsId]
     * @Return: java.util.List<com.weiyu.bultrasound.core.model.entity.Files>
     * @Author: abner chow
     * @Date: 2019/8/20 18:03
     */
    @Override
    public List<Files> getSynchronizeList(Long applicationsId) {
        return filesMapper.getSynchronizeList(applicationsId);
    }
}
